package handler

import (
	"GoodOrder/global"
	"GoodOrder/model"
	"GoodOrder/proto"
	"context"
	"fmt"
	"github.com/smartwalle/xid"
)

type OrderServer struct {
}

// 生成订单
func (s *OrderServer) CreateOrder(ctx context.Context, req *proto.OrderRequest) (*proto.OrderResponse, error) {
	//生成订单
	var order model.Order
	var tradeNo = fmt.Sprintf("%d", xid.Next())
	order.OrderSnc = tradeNo
	order.UserId = req.UserId
	order.AmountPrice = 999
	global.DB.Create(&order)
	result := proto.OrderResponse{
		OrderSnc: order.OrderSnc,
	}
	return &result, nil
}

//// 获取订单列表
//func (s *OrderServer) GetOrder(ctx context.Context, req *proto.OrderSearchReq) (*proto.OrderMessageResponse, error) {
//	//查询订单及订单字表
//	var order []model.Order
//	page := int(req.Page)
//	pageSize := int(req.PageSize)
//	result := global.DB.Preload("OrderSnc").Offset(page).Limit(pageSize).Find(&order)
//	rsp := &proto.OrderMessageResponse{}
//	rsp.Total = int32(result.RowsAffected)
//
//}
